#include "../sylar/sylar.h"

sylar::Logger::ptr g_logger = SYLAR_LOG_ROOT();

void run_in_fiber()
{
    SYLAR_LOG_INFO(g_logger) << "run_in_fiber begin";
    sylar::Fiber::YieldToHold();
    SYLAR_LOG_INFO(g_logger) << "run_in_fiber end";
    sylar::Fiber::YieldToHold();
}

void test_fiber()
{

    auto ok_ = sylar::Fiber::GetThis();
    SYLAR_LOG_INFO(g_logger) << "main begin";
    SS()<< ok_.get() <<"  "; 
    sylar::Fiber::ptr fiber(new sylar::Fiber(run_in_fiber));
    fiber->swapIn();
    SYLAR_LOG_INFO(g_logger) << "main after swapin";
    fiber->swapIn();
    SYLAR_LOG_INFO(g_logger) << "main after end";
    fiber->swapIn();
}
int main(int argc, char **argv)
{

    // sylar::Thread::SetName("666");
    // SYLAR_LOG_INFO(g_logger) << "main begin real";
    // std::vector<sylar::Thread::ptr> vecs;
    // for (size_t i = 0; i < 5; ++i)
    // {
    //     vecs.push_back(std::make_shared<sylar::Thread>(test_fiber, "thread name " + std::to_string(i)));
    // }
    // for (size_t i = 0; i < 5; ++i)
    // {
    //     vecs[i]->join();
    // }
    //SYLAR_LOG_INFO(g_logger) << "main after end real";
    test_fiber();
    return 0;
}